<script setup>
import MyForm from "@/components/MyForm.vue";
import {shallowReactive, shallowRef} from "vue";
import {RULE} from "@/const";
import MyNav from "@/components/MyNav.vue";
import router from "@/router";
import {updateApi} from "@/api/AssetsApi";

// 获取资产记录
let assets = JSON.parse(sessionStorage.getItem('assets'));

// 表单项
let items = shallowRef([
  {'label': '资产名称', 'prop': 'title'},
  {'label': '资产图片', 'prop': 'picture'},
  {'label': '资产单价', 'prop': 'price'},
  {'label': '单价单位', 'prop': 'priceUnit'},

  {'label': '库存剩余', 'prop': 'stock'},
  {'label': '库存单位', 'prop': 'stockUnit'},

  {'label': '库存总计', 'prop': 'total'},
  {'label': '资产描述', 'prop': 'info', 'type': 'textarea'},
]);
// 表单默认值
let data = shallowReactive({
  'id': assets['id'],
  'title': assets['title'],
  'picture': assets['picture'],
  'price': assets['price'],
  'priceUnit': assets['priceUnit'],

  'stock': assets['stock'],
  'stockUnit': assets['stockUnit'],

  'total': assets['total'],
  'info': assets['info'],
});
// 表单规则
let rules = {
  'info': RULE.COMMON_INFO,
  'title': RULE.COMM_TITLE,
};
</script>

<template>

  <my-nav :items="[
  {'icon': 'User', 'label': '资产管理'},
  {'icon': 'User', 'label': '资产列表', 'url': '/rms/Assets'},
  {'icon': 'User', 'label': '修改资产'},
]"/>

  <el-divider/>
  <my-form type="update"
           :items="items"
           :data="data"
           :rules="rules"
           :api="updateApi"
           :fn="() => router.push('/rms/Assets')"
           :span="2"/>

</template>

<style scoped lang="scss">

</style>